package com.ruoyi.web.controller.credit;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.credit.domain.EvaTaskContract;
import com.ruoyi.credit.service.IEvaTaskContractService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务合同Controller
 *
 * @author ruoyi
 * @date 2022-03-10
 */
@Controller
@RequestMapping("/credit/taskContract")
public class EvaTaskContractController extends BaseController
{
    private String prefix = "credit/taskContract";

    @Autowired
    private IEvaTaskContractService evaTaskContractService;

    @RequiresPermissions("credit:taskContract:view")
    @GetMapping()
    public String taskContract()
    {
        return prefix + "/taskContract";
    }

    /**
     * 查询任务合同列表
     */
    @RequiresPermissions("credit:taskContract:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EvaTaskContract evaTaskContract)
    {
        startPage();
        List<EvaTaskContract> list = evaTaskContractService.selectEvaTaskContractList(evaTaskContract);
        return getDataTable(list);
    }

    /**
     * 导出任务合同列表
     */
    @RequiresPermissions("credit:taskContract:export")
    @Log(title = "任务合同", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EvaTaskContract evaTaskContract)
    {
        List<EvaTaskContract> list = evaTaskContractService.selectEvaTaskContractList(evaTaskContract);
        ExcelUtil<EvaTaskContract> util = new ExcelUtil<EvaTaskContract>(EvaTaskContract.class);
        return util.exportExcel(list, "任务合同数据");
    }

    /**
     * 新增任务合同
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存任务合同
     */
    @RequiresPermissions("credit:taskContract:add")
    @Log(title = "任务合同", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EvaTaskContract evaTaskContract)
    {
        return toAjax(evaTaskContractService.insertEvaTaskContract(evaTaskContract));
    }

    /**
     * 修改任务合同
     */
    @RequiresPermissions("credit:taskContract:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        EvaTaskContract evaTaskContract = evaTaskContractService.selectEvaTaskContractById(id);
        mmap.put("evaTaskContract", evaTaskContract);
        return prefix + "/edit";
    }

    /**
     * 修改保存任务合同
     */
    @RequiresPermissions("credit:taskContract:edit")
    @Log(title = "任务合同", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EvaTaskContract evaTaskContract)
    {
        return toAjax(evaTaskContractService.updateEvaTaskContract(evaTaskContract));
    }

    /**
     * 删除任务合同
     */
    @RequiresPermissions("credit:taskContract:remove")
    @Log(title = "任务合同", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(evaTaskContractService.deleteEvaTaskContractByIds(ids));
    }
}
